package com.jdk.demo.thread.completableFuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.function.BiFunction;
import java.util.function.Supplier;

//thenCombine 会把 两个 CompletionStage 的任务都执行完成后，把两个任务的结果一块交给 thenCombine 来处理
public class ThenCombineDemo {

	public static void main(String[] args) throws InterruptedException, ExecutionException {
		CompletableFuture<String> future1 = CompletableFuture.supplyAsync(new Supplier<String>() {
	        @Override
	        public String get() {
	            return "hello";
	        }
	    });
	    CompletableFuture<String> future2 = CompletableFuture.supplyAsync(new Supplier<String>() {
	        @Override
	        public String get() {
	            return "hello";
	        }
	    });
	    CompletableFuture<String> result = future1.thenCombine(future2, new BiFunction<String, String, String>() {
	        @Override
	        public String apply(String t, String u) {
	            return t+" "+u;
	        }
	    });

	    System.out.println(result.get());
	}

}
